package Andrew;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;

public class DiscoveryTest {
	JmDNS discover;
	ServiceInfo info;

	public void registerService(final String type, final String name,
			final Integer port, final Map<String, String> settings) {
		try {
			discover = JmDNS.create();
		} catch (final IOException e) {
			System.out.println("JmDNS could not be launched");
		}
		try {
			System.out.println("working...");
			info = ServiceInfo.create(type, name, port, 1, 1, settings);
			discover.registerService(info);
			System.out.println(info.getServer());
		} catch (final IOException e) {
			System.out.println("Failed to register service");
		}

	}

	public static void main(final String[] args) {
		final DiscoveryTest jm = new DiscoveryTest();
		// I don't know what this is for
		final ConcurrentHashMap<String, String> settings = new ConcurrentHashMap<String, String>();
		settings.put("param1", "value1");
		settings.put("param2", "value2");
		// should identify instances of HTTP running over TCP on the local link
		// ?at port 8001?
		jm.registerService("_http._tcp.local.", "MyService", 8001, settings);
		jm.discover.close();
	}
}
